//
//  FQWKWebView.m
//  KDFDApp
//
//  Created by haoran on 17/4/28.
//  Copyright © 2017年 cailiang. All rights reserved.
//

#import "FQWKWebView.h"
#import <WebKit/WKWebView.h>
#import "FQWKWebViewJSHanlder.h"
@interface FQWKWebView()
@property (nonatomic, strong) FQWKWebViewJSHanlder *jsHandler;

@end

@implementation FQWKWebView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self config];
    }
    return self;
}
- (FQWKWebViewJSHanlder *)jsHandler
{
    if (!_jsHandler) {
        _jsHandler = [[FQWKWebViewJSHanlder alloc]init];
    }
    return _jsHandler;
}
- (WKProcessPool *)shareProcessPool
{
    static WKProcessPool  *processPool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        processPool = [[WKProcessPool alloc]init];
    });
    return  processPool;
}
#pragma mark - 配置
- (void)config{
    {
//    WKUserContentController* userContentController = WKUserContentController.new;
//    [userContentController addScriptMessageHandler:self.jsHandler name:@"QCJSInterface"];
//    WKWebViewConfiguration* webViewConfig = WKWebViewConfiguration.new;
//    webViewConfig.userContentController = userContentController;
//    webViewConfig.processPool =  [self shareProcessPool];
//    NSString *cookieValue = [NSString stringWithFormat:@"document.cookie='SESSIONID=%@'",[UserManager sharedUser].sessionId];
//    WKUserScript * cookieScript = [[WKUserScript alloc]
//                                   initWithSource: cookieValue
//                                   injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
//    [userContentController addUserScript:cookieScript];
    [self.configuration.userContentController addScriptMessageHandler:self.jsHandler name:@"QCJSInterface"];
//    self.configuration.processPool = [self shareProcessPool];
    _jsHandler.webView = self;
    [_jsHandler registerJSApiAction];
    }
}
@end
